﻿using System.Text;

namespace Sex
{
	public partial class Sex : System.Web.UI.Page
	{
        public class ListExif : MyList
        {
            public ListExif(State MyState) : base (MyState, "Exif Data", "ExifName", new string[] { "Value", "Id-Dec", "Id-Hex", "Type", "TypeS", "Len" })
            {
                System.Drawing.Image imgFile = System.Drawing.Image.FromFile(MyState.CurrentPathAbs);
                System.Drawing.Imaging.PropertyItem[] Image_pi = imgFile.PropertyItems;
                imgFile.Dispose();
                for (int i = 0; i < Image_pi.Length; i++)
                {
                    string Value = "";
                    switch (Image_pi[i].Type)
                    {
                        case 1:
                            break;
                        case 2:
                            Value = Encoding.ASCII.GetString(Image_pi[i].Value, 0, Image_pi[i].Len - 1);
                            Value = Value.Trim();
                            // Value = Value.Replace(" ", "_");
                            // Value = XmlConvert.EncodeName(Value);
                            break;
                        case 3:
                            Value = ((int)(Image_pi[i].Value[0]) + (int)(Image_pi[i].Value[1] * 256)).ToString();
                            break;
                        case 4:
                            Value = ((int)(Image_pi[i].Value[0]) + (int)(Image_pi[i].Value[1] * 256) + (int)(Image_pi[i].Value[2] * 65536) + (int)(Image_pi[i].Value[3] * 65536 * 256)).ToString();
                            break;
                        case 5:
                        case 10:
                            Value = ((int)(Image_pi[i].Value[0]) + (int)(Image_pi[i].Value[1] * 256) + (int)(Image_pi[i].Value[2] * 65536) + (int)(Image_pi[i].Value[3] * 65536 * 256)).ToString() +
                                "/" +
                                ((int)(Image_pi[i].Value[4]) + (int)(Image_pi[i].Value[5] * 256) + (int)(Image_pi[i].Value[6] * 65536) + (int)(Image_pi[i].Value[7] * 65536 * 256)).ToString();
                            break;
                        case 6:
                            break;
                        case 7:
                            // liefert nur BinärDaten
                            // Value = Encoding.ASCII.GetString(Image_pi[i].Value);
                            // Value = XmlConvert.EncodeName(Value);
                            Value = "binary data";
                            break;
                        default:
                            break;
                    }
                    string s = "";
                    switch (Image_pi[i].Type)
                    {
                        case 1:
                            s = "byte[]";
                            break;
                        case 2:
                            s = "string";
                            break;
                        case 3:
                            s = "int16";
                            break;
                        case 4:
                            s = "int32";
                            break;
                        case 5:
                            s = "ulong[,]";
                            break;
                        case 6:
                            s = "bytex[]";
                            break;
                        case 7:
                            s = "int32[]";
                            break;
                        case 10:
                            s = "long[,]";
                            break;
                        default:
                            s = "undefined";
                            break;
                    }
                    if (Value != "")
                    {
                        Add(Exif.GetName(Image_pi[i].Id), new string[]
                    { 
                        Value, 
                        Image_pi[i].Id.ToString(), 
                        Hex.ToHex(Image_pi[i].Id), 
                        Image_pi[i].Type.ToString(), 
                        s, 
                        Image_pi[i].Len.ToString() 
                    });
                    }
                }
            }
        }
    }
}